import api from '../../../api/apis'
export default{
    namespaced:true,
    state:{
       page:{
           currentPage:1,
           pageSize:10
       },
       pages:0,
       total:0,
       viprender:[],
       firstHalf:[],
       secondHalf:[],
       memberName1:{
        memberName: "",
        memberPhoneNumber: "",
       }
    },
    actions:{
        async addviper (context,data){
            const data1 = await  api.vip.addvip(data)
            console.log(data1);
              
        },
        async getvips(context,data){
            // console.log(data);
            const data1 = await api.vip.getvip({
                currentPage:context.state.page.currentPage,
                pageSize:context.state.page.pageSize,
                data:{memberName:context.state.memberName1.memberName,
                memberPhoneNumber:context.state.memberName1.memberPhoneNumber}
            })
            //    console.log(data1);
            //    context.commit('setvip',data1)
        },
        async getguashi(context,data){
            //   console.log(data);
            const dd = await api.vip.guashi(data)
            //   console.log(dd);
        }
    },
    mutations:{
        setvip(state,data){
            data.data.data.data.forEach(e=> {
                // console.log(e);
             if(e.memberVipLevelId == 1){
                e.memberVipLevelId = '普通会员'
             }else if(e.memberVipLevelId ==2){
                e.memberVipLevelId = '黄金会员'
             }else if(e.memberVipLevelId == 3){
                e.memberVipLevelId  ='钻石会员'
             }else{
                e.memberVipLevelId = '暂无数据'
             }
          });
            

            state.pages =data.data.data.pages
            state. total =data.data.data.total
            state.viprender=data.data.data.data
        
             
       
            const half = Math.ceil(state.viprender.length / 2);    
 
state.firstHalf = state.viprender.splice(0, half)
state.secondHalf = state.viprender.splice(-half)
        },
        setpagesize(state,val){
          
            state.page.pageSize =val
        },
        setcurrentpage(state,val){
            state.page.currentPage =val
        },
        findvip(state,val){
            state.memberName1 = val
            // console.log(val);
        }
    }
}